Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 23, 2025

Summary: Add Variable Support Tests to Egg ✅

Successfully implemented variable-based versions of all existing egg tests as requested in issue "egg的测试缺少对变量的支持".

Changes Made:

  • Understand the current test structure and how egg works
  • Create variable-based versions of existing tests:
    • test_egg_symmetry_with_variables: Tests symmetry with variables
    • test_egg_transitivity_with_variables: Tests transitivity with variables (the main example from the issue: a(\x) == b(`x), b(`x) == c(`x)a(t) == c(t)`)
    • test_egg_congruence_with_variables: Tests congruence with nested structures: a(\x)=b(`x)f(a(t))=f(b(t))`
    • test_egg_substitution_with_variables: Tests substitution with nested structures: f(a(\x)), a(`x)=b(`x)f(b(t))`
    • test_egg_complex_situation_with_variables: Tests comprehensive combination of variable and concrete facts
  • All tests passing (11/11 tests pass)
  • Code review completed and feedback addressed
  • Improved docstrings for clarity
  • Security check completed with CodeQL (0 issues found)

Technical Details:

  • Variables use backtick (`) prefix as supported by the apyds library
  • Variable patterns use proper syntax: (unary a \x)` for function application
  • Tests demonstrate that variables can match any concrete term through unification
  • The system correctly derives concrete instances from variable patterns
  • Congruence and substitution work with nested function applications derived from variable patterns
Original prompt

This section details on the original issue you should resolve

<issue_title>egg的测试缺少对变量的支持</issue_title>
<issue_description>几乎前面所有的基础测试都需要来一份带变量版本的测试.

以 a=b, b=c 得到 a=c 为例

a(x) == b(x), b(x) == c(x) 应该可以判断出 a(t) == c(t)

这里的含有 "`" 的就是变量, 可以匹配任意东西.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 23, 2025
Copilot AI and others added 3 commits December 23, 2025 02:28
Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add variable support to basic tests Add variable pattern tests for egg Dec 23, 2025
Copilot AI requested a review from hzhangxyz December 23, 2025 02:32
- Congruence test now correctly tests: a(`x)=b(`x) → f(a(t))=f(b(t))
- Substitution test now correctly tests: f(a(`x)), a(`x)=b(`x) → f(b(t))
Both tests now use nested function applications as intended

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
@hzhangxyz hzhangxyz marked this pull request as ready for review December 23, 2025 02:50
Copilot AI review requested due to automatic review settings December 23, 2025 02:50
@hzhangxyz hzhangxyz merged commit 30ab169 into main Dec 23, 2025
14 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive variable pattern support tests to the egg testing suite, addressing issue #28. The tests demonstrate that variable patterns (using backtick notation like `x) can match any concrete term through unification, and verify that the system correctly derives concrete instances from variable patterns.

Key Changes:

  • Added five new test functions that mirror existing tests but use variable patterns instead of concrete terms
  • Tests verify symmetry, transitivity, congruence, substitution, and complex combinations work with variables
  • All tests follow the existing testing patterns and use the same test fixture infrastructure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +218 to +224
task = asyncio.create_task(main(addr, engine, session))
await asyncio.sleep(0.3)
task.cancel()
try:
await task
except asyncio.CancelledError:
pass
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test setup and teardown logic is duplicated across all five new test functions. Consider extracting the common pattern of creating a task, waiting 0.3 seconds, cancelling it, and handling CancelledError into a helper function or fixture to reduce duplication and improve maintainability. This pattern appears in lines 218-224, 246-252, 280-286, 318-324, and 374-380.

Copilot uses AI. Check for mistakes.
task.cancel()
try:
await task
except asyncio.CancelledError:
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
task.cancel()
try:
await task
except asyncio.CancelledError:
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
try:
await task
except asyncio.CancelledError:
pass
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
pass
# The task is expected to be cancelled as part of this test.
assert task.cancelled()

Copilot uses AI. Check for mistakes.
task.cancel()
try:
await task
except asyncio.CancelledError:
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
except asyncio.CancelledError:
except asyncio.CancelledError:
# Expected when stopping the background task during test teardown.

Copilot uses AI. Check for mistakes.
task.cancel()
try:
await task
except asyncio.CancelledError:
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
except asyncio.CancelledError:
except asyncio.CancelledError:
# Task cancellation is expected here: we stop the background `main` loop for this test.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

egg的测试缺少对变量的支持

2 participants